home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 3623 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.8 KB  |  61 lines

  1. Path: news.primenet.com!ip125
  2. From: mcoplea@primenet.com (Marty R. Coplea)
  3. Newsgroups: comp.lang.c
  4. Subject: Simple i/o for my class
  5. Date: 30 Jan 1996 01:11:01 -0700
  6. Organization: Primenet
  7. Sender: root@primenet.com
  8. Message-ID: <4ekjql$5jl@nnrp1.news.primenet.com>
  9. X-Posted-By: ip125.phx.primenet.com
  10. X-Newsreader: News Xpress Version 1.0 Beta #4
  11.  
  12. I am having a little trouble with a batting average program.
  13. It seems to take the input OK, but always returns a '0' for the Batting 
  14. Average.  Please look at the following code and make any suggestions.  Thank 
  15. you in advance for any assistance you can offer. (email perfered)
  16.  
  17. /***********************************
  18.     DESIGN:
  19.     Prompt the user to enter the number of at bats and the number of hits.
  20.     Calculate the batting average (number of hits / number of at bats)
  21.     Print out the result with 3 significant places to the right of the
  22.     decimal point and make sure that the average does not round up.
  23.     Report the results back to the user.
  24.  
  25.     TEST PLAN:
  26.     Large Number / Large Number (11,000 / 2,125)
  27.     Large Number / Small Number (12,000 / 33)
  28.     Small Number / Small Number (15 / 6)
  29.     Large Number / Zero (12,121 / 0)
  30.     Small Number / Zero (5 / 0)
  31.  
  32. ************************************/
  33.  
  34. #include <stdio.h>
  35.  
  36. int
  37. main(void)
  38. {
  39.     float avar, hvar;      /*float variables(avar=At-bats,hvar=Hits */
  40.     int Hitsint, Atbatsint;       /* Integers with Hits and At Bats */
  41.     float Avg;           /* Results Batting Average */
  42.  
  43.     /* Prompt the user to input the data */
  44.     printf("Enter the number of at-bats followed by hits:   ");
  45.     scanf("%f %f", &avar, &hvar);
  46.  
  47.     /* Convert to integers */
  48.     Atbatsint = avar;
  49.     Hitsint = hvar;
  50.  
  51.     /* Calculate the Batting Average */
  52.     Avg = Hitsint/Atbatsint;
  53.  
  54.     /* Return results to user */
  55.     printf("Batting Average = %.2f\n", Avg);
  56.  
  57.     return 0;             /* We done */
  58. }
  59.  
  60.  
  61.